# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=libwps
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.4.14
pkgrel=1
pkgdesc="A library for reading Microsoft Works word processor documents. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://sourceforge.net/projects/libwps/'
msys2_references=(
  'archlinux: libwps'
)
license=('spdx:MPL-2.0 OR LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-librevenge")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://downloads.sourceforge.net/project/${_realname}/${_realname}/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.xz"
        "001-fix-build-on-mingw.patch")
sha256sums=('365b968e270e85a8469c6b160aa6af5619a4e6c995dbb04c1ecc1b4dd13e80de'
            '8a282f1760c7a0aac00e9d8d314378bcfda8cbda51c0c9efa2bd3ced86014233')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/001-fix-build-on-mingw.patch

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../"${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}"

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

  install -d "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  install -p -m644 "${srcdir}"/${_realname}-${pkgver}/COPYING* "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
